package IndusmecaSI.Indusmeca_Controller
{
	import mx.collections.ArrayCollection;
	
	import valueObjects.User;
	
	public class Controller_Login
	{
		import mx.controls.Alert; 
		import IndusmecaSI.Indusmeca_Model.Model_User_Service;
		import mx.core.FlexGlobals;
		
		private var listcomp:Model_User_Service = new Model_User_Service();
		private var formSource:Object;
		private var user:User;
		public function Controller_Login(FormSource:Object)
		{
			this.formSource = FormSource;
		}
		
		public function Validation_Login(user:User):void
		{
			this.user = user;
			listcomp.getUserByUser(this,formSource,user);
			
		}
		
		
		public function validForm(user:User):void
		{
			
			if (formSource.currentState.valueOf() == 'MenuLogin'){
				
				var cState:String = FlexGlobals.topLevelApplication.currentState.valueOf();
				if ( cState == 'Login' && this.user.LOGIN == user.LOGIN && this.user.PASSWORD == user.PASSWORD && this.user.id_company == user.id_company){ //&& txt_Login.text == user.LOGIN &&	txt_Password.text == user.PASSWORD){
					FlexGlobals.topLevelApplication.setLbBienvenue(user.firstname,user.ID_USER);
					FlexGlobals.topLevelApplication.currentState='Accueil';
				}
				else{
					Alert.show('Utilisateur inconnu');
				}
			}else
			{
				Alert.show('Enregistrement Réussi'+'\n\nCompte en cours \nde validation');
			}
			
		}
		
		public function Validation_Inscription(user:User):void
		{
			
			
			listcomp.createUser(this,formSource,user);
			
			Alert.show('click inscription');	
		}
		
		public function loadListSociete():void
		{
			var listcomp:Model_User_Service = new Model_User_Service();
			listcomp.getAllCompany(this,formSource);
		}
		
	}
}